package com.base.cn.platform.os.controller.op.giftcard;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.service.manage.op.giftcard.OpGiftCardCodeService;
import com.base.cn.platform.os.service.manage.op.giftcard.OpGiftCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 礼品卡编码1
 * @author ll
 * @date 2018/5/16 11:03
 */
@Controller
@RequestMapping("/admin/op/giftCard")
public class AdminOpGiftCardCodeController extends AdminBaseController {

    @Autowired
    private OpGiftCardCodeService opGiftCardCodeService;
    @Autowired
    private OpGiftCardService opGiftCardService;
    /**
     * 搜索礼品卡编码券
     * @param currentPage
     * @param opGiftCardCode
     * @return
     */
    @RequestMapping("/queryOpGiftCardCodeListPage")
    public String queryOpGiftCardCodeListPage(Model model,
                                              @RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage,
                                              @RequestBody Map<String,Object> opGiftCardCode){
        Map<String,Object> dataMap =opGiftCardCodeService.queryOpGiftCardCodeListPage(currentPage,opGiftCardCode,true,true,false);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/op/giftcard/giftCardCode_ajax_list");
    }
    /**
     * 导出礼品卡
     * @param giftCardId
     * @param useType
     * @return
     * @throws IOException
     */
    @RequestMapping("/downloadExcelGiftCardList")
    public ResponseEntity<byte[]> downloadExcelOpCoupon(@RequestParam(value = "giftCardId") BigDecimal giftCardId,@RequestParam(value = "useType",required = false) Integer useType) throws IOException {
        Map<String,Object> params= new HashMap<>();
        params.put("giftCardId",giftCardId);
        if(ObjectUtils.isNotEmpty(useType)){
            params.put("useType",useType);
        }
        return opGiftCardService.downloadExcelGiftCardList(giftCardId,useType);

    }


}
